/**
 * 
 */
package com.googlecode.flair.flexsdk;

import java.util.Map;

import org.jdom.CDATA;
import org.jdom.Element;

/**
 * @author ccPascu
 * 
 */
public class FlexStyle {

	private String name;
	private String type;
	private String enumeration;
	private boolean inherit;
	private String states;
	private String arrayType;
	private String format;
	private String documentation;
	
	private FlexComponentClass componentClass;

	public FlexStyle(Map<String, String> properties) {
		this.name = properties.get("name");
		this.type = properties.get("type");
		this.enumeration = properties.get("enumeration");
		this.states = properties.get("states");
		this.inherit = "no".equals(properties.get("inherit")) ? false : true;
		this.arrayType = properties.get("arrayType");
		this.format = properties.get("format");
	}

	public Element toXml() {
		Element styleElement = new Element("style").setAttribute("name", name);
		if (type != null) {
			styleElement.setAttribute("type", type);
		}
		if (enumeration != null) {
			styleElement.setAttribute("enumeration", enumeration);
		}
		if (states != null) {
			styleElement.setAttribute("states", this.states);
		}
		if (arrayType != null) {
			styleElement.setAttribute("arrayType", this.arrayType);
		}
		if (format != null) {
			styleElement.setAttribute("format", this.format);
		}
		styleElement.setAttribute("inherit", inherit ? "true" : "false");
		if (documentation != null) {
			styleElement.addContent(new Element("documentation").setContent(new CDATA(documentation)));
		}
		return styleElement;
	}
	
	
	/**
	 * @param componentClass
	 */
	public void setComponentClass(FlexComponentClass componentClass) {
		this.componentClass = componentClass;
	}
	
	/**
	 * @return
	 */
	public FlexComponentClass getComponentClass() {
		return componentClass;
	}
	
	public String getName() {
		return name;
	}

	/**
	 * @return the type
	 */
	public final String getType() {
		return type;
	}

	/**
	 * @return the enumeration
	 */
	public final String getEnumeration() {
		return enumeration;
	}

	/**
	 * @return the inherit
	 */
	public final boolean isInherit() {
		return inherit;
	}

	/**
	 * @return the states
	 */
	public final String getStates() {
		return states;
	}

	/**
	 * @return the arrayType
	 */
	public final String getArrayType() {
		return arrayType;
	}

	/**
	 * @return the format
	 */
	public final String getFormat() {
		return format;
	}
	
	/**
	 * @param documentation
	 */
	public void setDocumentation(String documentation) {
		this.documentation = documentation;
	}
	
}
